<!--
  Copyright © 2015 Cask Data, Inc.

  Licensed under the Apache License, Version 2.0 (the "License"); you may not
  use this file except in compliance with the License. You may obtain a copy of
  the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  License for the specific language governing permissions and limitations under
  the License.
-->

<div class="container">
  <div class="alerts">
    <div class="alert alert-danger" ng-if="error.content">
      <button type="button" class="close" ng-click="error.content=false">×</button>
      <span>{{error.content}}</span>
    </div>
  </div>
  <div class="schedule-heading row">

    <div class="col-xs-offset-1 col-xs-3">
      <h4>Schedule Name</h4>
    </div>
    <div class="col-xs-4">
      <h4>Description</h4>
    </div>
    <div class="col-xs-2">
      <h4>Last Run</h4>
    </div>
    <div class="col-xs-2">
    </div>
  </div>

  <div class="schedule-content">
    <div class="schedule-rows" ng-repeat="schedule in schedules">
      <div class="row schedule-row"
        ng-click="schedule.isOpen = !schedule.isOpen"
        ng-class="{ 'active': schedule.isOpen }">
        <div class="col-xs-1">
          <i class="fa"
          ng-class="{'fa-chevron-down': schedule.isOpen, 'fa-chevron-right': !schedule.isOpen}"></i>
        </div>

        <div class="col-xs-3">
          <p  uib-tooltip="{{ schedule.name }}"
              tooltip-placement="right"
              tooltip-enable="schedule.name.length > 31"
              tooltip-append-to-body="true">
            {{ schedule.name | myEllipsis: 31 }}
          </p>
        </div>

        <div class="col-xs-4">
          <p  uib-tooltip="{{ schedule.description }}"
              tooltip-placement="right"
              tooltip-enable="schedule.description.length > 50"
              tooltip-append-to-body="true">
              {{ schedule.description | myEllipsis: 50 }}
          </p>
        </div>

        <!-- Last run information API is not available yet. We should add it once it comes up -->

        <div class="col-xs-2">
          <p>{{ schedule.status }}</p>
        </div>
      </div>

      <div class="row schedule-detail" ng-if="schedule.isOpen">
        <div class="row">
          <div class="col-xs-offset-2 col-xs-2">
            <p>Trigger</p>
          </div>
          <div class="col-xs-6">
            <p>{{ schedule.scheduleType }}</p>
          </div>
          <div class="col-xs-2">
            <button class="btn btn-default"
              ng-disabled="disableSchedule"
              ng-if="schedule.status === 'SCHEDULED'"
              ng-click="takeScheduleAction(schedule, 'pause')">
              <i class="fa fa-pause"></i>
            </button>

            <button class="btn btn-default"
              ng-disabled="disableSchedule"
              ng-if="schedule.status === 'SUSPENDED'"
              ng-click="takeScheduleAction(schedule, 'resume')">
              <i class="fa fa-play"></i>
            </button>

            <button class="btn btn-default"
             ng-if="['SUSPENDED', 'SCHEDULED'].indexOf(schedule.status) === -1"
             disabled>
              <i class="fa fa-refresh fa-spin"></i>
            </button>
          </div>
        </div>
        <div class="row">
          <div ng-if="schedule.scheduleType === 'TIME'">
            <div class="col-xs-offset-2 col-xs-2">
              <p>Crontab</p>
            </div>

            <div class="col-xs-8">
              <my-cron-schedule-view ng-model="schedule.cronExpression">
              </my-cron-schedule-view
            </div>
          </div>


          <div ng-if="schedule.scheduleType === 'STREAM'">
            <div class="col-xs-offset-2 col-xs-2">
              <p>Data Trigger</p>
            </div>

            <div class="col-xs-8">
              <p>{{ schedule.schedule.dataTriggerMB }} MB</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
